/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 98152
 * Date: 2024-11-12
 * Time: 22:08
 */
import java.util.*;

class Student implements Comparable<Student>{
    public double t;//总得分
    public double z;//智育分
    public String s;//名字
    public Student(double t, double z, String s) {
        this.t = t;
        this.z = z;
        this.s = s;
    }
    public int compareTo(Student o) {
        double diffZ = o.z-this.z;
        if(diffZ > 0) {
            return 1;
        }else if(diffZ < 0) {
            return -1;
        }else {
            double diffT = o.t-this.t;
            if(diffT > 0) {
                return 1;
            }else if(diffT < 0){
                return -1;
            }else {
                return 0;
            }
        }
    }
    public String toString() {
        return this.s + " ";
    }
}

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        Student[] students = new Student[n];
        for(int i = 0; i < n; i++) {
            double t = in.nextDouble();
            double z = in.nextDouble();
            String s = in.nextLine();
            //String s = in.nextLine().trim();//吸收名字前面的空格
            students[i] = new Student(t, z, s);
        }
        Arrays.sort(students);

        StringBuilder result = new StringBuilder();
        for (Student student : students) {
            result.append(student.toString());
        }
        System.out.println(result.toString().trim());

        /*String studentsString = Arrays.toString(students);
        //去掉方法输出时的中括号和逗号
        String result = studentsString.substring(1, studentsString.length() - 1).replace(", ", "");
        System.out.println(result.trim());*/
    }
}